package entidadesBD;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import entidadesVO.*;

@Entity
@Table(name = "articulos_ofad")
public class ArticulosOFAD implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Articulo articulo;
	private float precioFinal;
	private OFAD ofad;
	
	private int codigoArticulosOFAD;

	public ArticulosOFAD(Articulo articulo, float precioFinal) {
		this.articulo = articulo;
		this.precioFinal = precioFinal;
	}
	public ArticulosOFAD(){
		//Constructor Vacio
	}

	@OneToOne
	@JoinColumn(name = "articulo")
	public Articulo getArticulo() {
		return articulo;
	}
	public void setArticulo(Articulo articulo) {
		this.articulo = articulo;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getCodigoArticulosOFAD() {
		return codigoArticulosOFAD;
	}
	public void setCodigoArticulosOFAD(int codigoArticulosOFAD) {
		this.codigoArticulosOFAD = codigoArticulosOFAD;
	}

	@ManyToOne
	public OFAD getOfad() {
		return ofad;
	}
	public void setOfad(OFAD ofad) {
		this.ofad = ofad;
	}
	
	@Column
	public float getPrecioFinal() {
		return precioFinal;
	}
	public void setPrecioFinal(float precioFinal) {
		this.precioFinal = precioFinal;
	}
	
	@Transient
	public ArticulosOFADVO getArticulosOFADVO(){
		
		ArticuloVO articuloVO = articulo.getArticuloVO();
	
		ArticulosOFADVO articulosOFADVO = new ArticulosOFADVO(articuloVO, precioFinal);
		
		articulosOFADVO.setCodigoArticulosOFAD(codigoArticulosOFAD);
		
		return articulosOFADVO;
	}
	
	public void setArticulosOFADVO(ArticulosOFADVO articulosOFADVO){
		
		this.precioFinal = articulosOFADVO.getPrecioFinal();
	}
}
